$(document).ready(function(){
    $show = $(".tour_shows");
    $items = $("a.items");
    $show.eq(0).show();
    $items.click(function(){
        $(".selected").removeClass("selected");
        $(this).addClass("selected");
        $val = $(this).attr("name");
        $show.hide();
        $show.eq($val).show();
        return false;
    });
});
$(document).ready(function() {
    //Thumbnailer.config.shaderOpacity = 1;
    var tn1 = $('.mygallery').tn3({
        skinDir:"skins",
        imageClick:"fullscreen",
		autoplay : true,
        image:{
            maxZoom:1.5,
            crop:true,
            clickEvent:"dblclick",
            transitions:[{
                type:"blinds"
            },{
                type:"grid"
            },{
                type:"grid",
                duration:460,
                easing:"easeInQuad",
                gridX:1,
                gridY:8,
                // flat, diagonal, circle, random
                sort:"random",
                sortReverse:false,
                diagonalStart:"bl",
                // fade, scale
                method:"scale",
                partDuration:360,
                partEasing:"easeOutSine",
                partDirection:"left"
            }]
        }
    });
});
function checkEmail(inputvalue){
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){
        return true;
    }else{
        return false;
    }
}
function isValidPhone(phone)
{
    var reg = /^[0-9-+]+$/;
    return reg.test(phone)
}
/***have us call news **/
function have() {
    var st = $("#status").change().val();
    //alert(st);
    var tname = $("#tname").change().val();
    var hname = $("#hname").val();
    var phonec = $("#phonec").val();
    var phone = $("#phone").val();
    var phonecall = $("#phonecall").val();
    var from = $("#from").val();
    var from2 = $("#from2").change().val();
    var to = $("#to").val();
    var to2 = $("#to2").change().val();
    var national = $("#national").change().val();
    $.ajax({
    type: "POST",
    dataType: "json",
    url: links+"home/call/thank",
    data: {st: st, tname: tname, hname: hname, phonec: phonec, phone: phone, phonecall: phonecall,from: from, from2: from2,
    to: to, to2: to2,national: national},
    success: function(resp) {
        if (resp.status == true) {
        $('#closes').hide();
        $('.thongbao').html(resp.sucsec);
        } else {
        $('.thongbao').html(resp.erro);
        }
    }
});
return false;
}
/**add contact **/
function contact() {
    var name = $('#namec').val();
    if(name == ''){
        alert('You must fill in this place');
        $('#namec').focus();
        return false;
    }
    var email = $('#mailc').val();
    if(checkEmail(email) == false){
        alert('Invalid email address');
        $('#mailc').focus();
        return false;
    }
    var coc = $('#coc').val();
    if(coc == ''){
        alert('You must fill in this place');
        $('#coc').focus();
        return false;
    }

    var sc = $.trim($('#sc').val());
    if(sc == ''){
        alert('You must fill in this place');
        $('#sc').focus();
        return false;
    }
    var finc = $('#finc').change().val();
    var mesc = $('#mesc').val();
    if(mesc == ''){
        alert('You must fill in this place');
        $('#mesc').focus();
        return false;
    }
    $.ajax({
        type: "post",
        url: links+"home/contact/add",
        data: {name:name, email:email, coc:coc, sc:sc, finc:finc, mesc:mesc},
        success: function(data){
            window.location = links+"thank.html";
        }
    });
    return false;
}
/** focus , blur***/
$(function() {
    $("#date1").datepicker();
    $("#date_b").datepicker();
    $("#date_cus").datepicker();
    $("a.example1").fancybox();
});
$(function() {
    $("#date2").datepicker();
});

function ashowvisa(){
    $('#visashow').show();
    $('#visahiden').hide();
}
/**** quick ques ***/
function ques() {

    var nameq = $('#nameq').val();
    if(nameq == '') {
        alert('You must fill in this place');
        $('#nameq').focus();
        return false;
    }
    var mailq = $('#mailq').val();
    if(checkEmail(mailq) == false){
        $('#mailq').focus();
        alert('Invalid email address');
        return false;
    }
    var content = $('#ctq').val();
    if(content == '') {
        alert('You must fill in this place');
        $('#ctq').focus();
        return false;
    }
    $.ajax({
        url: links+"home/ques/add",
        type: 'post',
        data: {content:content, nameq:nameq, mailq:mailq},
        success: function(data){
            var name_q = $('#nameq').val('');
            var email_q = $('#mailq').val('');
            window.location = links+"thank.html";
        }
    });
    return false;
}
//form customize tour
function custour() {
    var name = $('#ftname').val();
    if(name == ''){
        alert('You must fill in this place');
        $('#ftname').focus();
        return false;
    }
    var phone = $('#ftphone').val();
    if( isValidPhone(phone) == false){
        $('#ftphone').focus();
        alert('Invalid phone');
        return false;
    }
    var mail = $('#ftemail').val();
    if(checkEmail(mail) == false){
        $('#ftemail').focus();
        alert('Invalid email address');
        return false;
    }
    var ftor = $('#ftor').val();
    var adress = $('#ftadress').val();
    var content = $('#ftcontent').val();
    var tour_id = $('#tourf_id').val();
    if(content == ''){
        alert('You must fill in this place');
        $('#ftcontent').focus();
        return false;
    }
    $.ajax({
       type:'post',
        url: links + "home/tours/custours",
        data:{name:name, phone:phone, mail:mail, ftor:ftor, adress:adress, content:content, tour_id:tour_id},
        success: function(){
            var name = $('#ftname').val('');
            var phone = $('#ftphone').val('');
            var mail = $('#ftemail').val('');
            var ftor = $('#ftor').val('');
            var adress = $('#ftadress').val('');
            var content = $('#ftcontent').val('');
            window.location = links+"thank.html";
        }
    });
    return false;
}
function book() {
    var name_b = $('#name_b').val();
    if(name_b == ''){
        alert('You must fill in this place');
        $('#name_b').focus();
        return false;
    }
    var mail_b = $('#mail_b').val();
    if(checkEmail(mail_b) == false){
        $('#mail_b').focus();
        alert('Invalid email address');
        return false;
    }
    var con_b = $('#con_b').val();
    var add_b = $('#add_b').val();
    var phone_b = $('#phone_b').val();
    if( isValidPhone(phone_b) == false){
        $('#phone_b').focus();
        alert('Invalid phone');
        return false;
    }
    var tname_b = $('#tname_b').val();
    var tid_b = $('#tid_b').val();
    var adu_b = $('#adu_b').val();
    if(adu_b == ''){
        alert('You must fill in this place');
        $('#adu_b').focus();
        return false;
    }
    var chi_b = $('#chi_b').val();
    var date_b = $('#date_b').val();
    if(date_b == ''){
        alert('You must fill in this place');
        $('#date_b').focus();
        return false;
    }
    if($("input[type='radio'].diet").is(':checked')) {
        var diet = $("input[type='radio'].diet:checked").val();
    }else {
        var diet = 0;
    }
    if($("input[type='radio'].call_b").is(':checked')) {
        var call_b = $("input[type='radio'].call_b:checked").val();
    }else {
        var call_b = 0;
    }
    var indi_b = $('#indi_b').val();
    var find_b = $('#find_b').change().val();
    var conten_b = $('#conten_b').val();

    $.ajax({
        type:'post',
        url: links + "home/tours/book",
        data:{name_b:name_b, mail_b:mail_b, con_b:con_b, add_b:add_b, phone_b:phone_b, tname_b:tname_b, tid_b:tid_b,
            adu_b:adu_b, chi_b:chi_b, date_b:date_b, diet:diet, call_b:call_b, indi_b:indi_b, find_b:find_b, conten_b:conten_b},
        beforeSend : function(){
            $("#loading").html("<img src='"+links+"public/images/loading.gif' /> Processing...");
        },
        success: function(){
            $('#name_b').val('');
            $('#mail_b').val('');
            $('#phone_b').val('');
            $('#con_b').val('');
            $('#add_b').val('');
            $('#date_b').val('');
            $('#adu_b').val('');
            $('#chi_b').val('');
            $('#indi_b').val('');
            $('#conten_b').val('');
            window.location = links+"thank.html";
        }
    });
    return false;
}